Release 10.1A: OpenEdge Development:
Messaging and ESB


Publishing with a reply handle, subscribing, and receiving an automatic reply

The procedures example5.p, example6.p (1 of 2), and example7.p illustrate publishing with a reply handle and receiving an automatic reply. The procedure example5.p subscribes with an automatic reply mechanism. It can only reply to messages that have the JMSReplyTo header field. The procedure example6.p (1 of 2) subscribes with explicit reply by calling the publish procedure directly. It can only reply to messages that have the JMSReplyTo header field. The procedure example7.p publishes using the requestReply procedure for receiving reply messages from subscribers. It populates the JMSReplyTo header field automatically.

To run example5.p, example6.p and example7.p:

  1. Run example5.p so the subscriber is running before you publish, as shown:
  2. example5.p 
    /* Using the automatic reply mechanism. Note that the received message
       must have a JMSReplyTo header field for this to work. Example7 can be
       used to receive the reply.  */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Subscribe to the GolfTopic topic. Messages are handled by the 
       "golfHandler" internal procedure.  */ 
    RUN createMessageConsumer IN pubsubsession ( 
                          THIS-PROCEDURE,   /* This proc will handle it */ 
                          "golfHandler",    /* name of internal procedure */ 
                          OUTPUT consumerH). 
    RUN subscribe IN pubsubsession (
                             "GolfTopic",  /* name of topic */ 
                             ?,              /* Subscription is not durable */ 
                             ?,            /* No message selector */ 
                             no,           /* Want my own messages too */ 
                             consumerH).   /* Handles the messages */ 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN pubsubsession. 
    /* Wait forever to receive messages since "u1" is never applied.  */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    
    PROCEDURE golfHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
        /* Creates a reply message. The reply is published automatically when
           control returns to the 4GL-JMS implementation. 
        */ 
        DISPLAY DYNAMIC-FUNCTION('getText':U IN messageH) format "x(60)". 
        IF DYNAMIC-FUNCTION('hasReplyTo':U IN messageH) THEN  
          DO: 
            RUN createTextMessage IN pubsubsession (OUTPUT replyH). 
            RUN setText IN replyH ("Will bid. Send data in sportsXML 
                                   format."). 
          END. 
        RUN deleteMessage IN messageH. 
    END. 
    

  3. Run example6.p (1 of 2) to subscribe with explicit reply by calling the publish procedure directly, as shown:
  4. example6.p
    /* Replying explicitly. Note that the received message must 
       have a JMSReplyTo header field for this to work. Example7 can be used 
       to receive the reply.  */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE msgConsumer AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    RUN createMessageConsumer IN pubsubsession ( 
                           THIS-PROCEDURE,  /* This proc will handle it */ 
                           "messageHandler", /* name of internal procedure */ 
                           OUTPUT msgConsumer). 
    RUN subscribe IN pubsubsession (
                                  "GolfTopic", 
                                  ?,  /* No durable subscription */ 
                                  ?,  /* No message selector */ 
                                  no, /* Want to get my own publications */ 
                                  msgConsumer). 
    RUN startReceiveMessages IN pubsubsession. 
    /* Wait forever to receive messages since "u1" is never applied.  */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    RUN deleteSession IN pubsubsession. 
    
    PROCEDURE messageHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE NO-UNDO. 
    DEFINE INPUT PARAMETER messageConsumerH AS HANDLE NO-UNDO. 
    DEFINE OUTPUT PARAMETER autoReplyH AS HANDLE NO-UNDO.
    /* Not used in this example */ 
    DEFINE VARIABLE replyH AS HANDLE. 
        DISPLAY DYNAMIC-FUNCTION('getText':U IN messageH) format "x(60)". 
        IF NOT DYNAMIC-FUNCTION('hasReplyTo':U IN messageH) THEN RETURN. 
        /* Publishes a reply explicitly - using the publish call. */ 
        RUN createTextMessage IN pubsubsession (OUTPUT replyH). 
        RUN setText IN replyH("Will bid. Send data in sportsXML format."). 
        RUN publish IN pubsubsession (DYNAMIC-FUNCTION 
                                        ('getJMSReplyTo':U IN
                                          messageH), replyH, ?, ?, ?). 
        RUN deleteMessage IN messageH. 
        /* After we have sent the message, delete it. */ 
        RUN deleteMessage IN replyH. 
    END. 
    

  5. Run example7.p to publish using the requestReply procedure for receiving reply messages from subscribers. It populates the JMSReplyTo header field automatically, as shown:
  6. example7.p 
    /* Publishes a message and receives a reply. */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    DEFINE VARIABLE messageH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN pubsubsession. 
    /* Create a text message */ 
    RUN createTextMessage IN pubsubsession (OUTPUT messageH). 
    RUN setText IN messageH ("Golf shoes on sale today."). 
    /* Creates a consumer for the reply  */ 
    RUN createMessageConsumer IN pubsubsession ( 
                          THIS-PROCEDURE, /* This proc will handle it */ 
                          "golfHandler",  /* name of internal procedure */ 
                          OUTPUT consumerH). 
    /* Publish the message onto the Golf topic. Handle the reply in the  
       golfHandler internal procedure.  
    */ 
    RUN requestReply IN pubsubsession ( 
                                "GolfTopic", 
                                messageH, 
                                ?,         /* No reply selector. */ 
                                consumerH, ?, ?, ?).  
    RUN deleteMessage IN messageH. 
    
    /* Wait forever to receive messages since "u1" is never applied.  */ 
    WAIT-FOR u1 OF THIS-PROCEDURE.PROCEDURE golfHandler: 
    DEFINE INPUT PARAMETER replyH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER responseH AS HANDLE. 
    /* Display the reply - we are not sending a response. */ 
    DISPLAY "reply text: " DYNAMIC-FUNCTION('getText':U IN replyH)
      FORMAT "X(30)". 
    RUN deleteMessage IN replyH. 
    END. 
    


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095